/*
 * @Author: Anan 
 * @Date: 2022-05-09 22:49:52 
 * @Last Modified by: Anan
 * @Last Modified time: 2022-05-16 16:47:40
 */



import { Effect, Reducer } from 'umi';
import { getProdTag, getSerachList } from '@/services'
import { IProdTag } from '@/types'

export interface ProdTagModelState {
  prodTagList: IProdTag[];
  serachLists: IProdTag[]
}

export interface ProdTagModelType {
  namespace: 'prodprodTag';
  state: ProdTagModelState;
  effects: {
    getProdTagList: Effect;
    getSerachProdTagList: Effect;
  };
  reducers: {
    save: Reducer<ProdTagModelState>;
  };
}

const ProdTagModel: ProdTagModelType = {
  namespace: 'prodprodTag',
  state: {
    prodTagList: [],
    serachLists: []
  },

  effects: {
    *getProdTagList({ payload }, { call, put }) {
      let result = yield call(getProdTag, payload);
      console.log(result);
      console.log(result.records, 'ProdTagList...');

      if (result) {
        yield put({
          type: 'save',
          payload: {
            prodTagList: result.records
          }
        })
      }
    },

    // 搜索数据
    *getSerachProdTagList({ payload }, { call, put }) {
      let result = yield call(getSerachList, payload)
      console.log(result);
      if (result) {
        yield put({
          type: 'save',
          payload: {
            serachLists: result.records
          }
        })
      }
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};

export default ProdTagModel;